package com.heima.kafka.listener;


import com.alibaba.fastjson.JSON;
import com.heima.kafka.pojo.User;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.List;


// 要被spring管理
@Component
public class HelloListener {


    // 消息监听器
    @KafkaListener(topics = "itcast-topic")
    public void onMsg(String message){
        if(!StringUtils.isEmpty(message)){
            System.out.println("接收到消息："+message);
        }
    }

    // 消息监听器
    @KafkaListener(topics = "user-topic")
    public void onMsg2(String message){
        if(!StringUtils.isEmpty(message)){
            System.out.println("接收到json消息："+message);
            User user = JSON.parseObject(message, User.class);
            System.out.println("user:"+user);
        }
    }
}
